from django.shortcuts import get_object_or_404
from django.http import HttpResponseRedirect, HttpResponsePermanentRedirect
from .models import Redirect

def redirect(request, path):
    to = get_object_or_404(Redirect, from_url=path)
    
    if to.permanent:
        return HttpResponsePermanentRedirect(to.to_url)
    else:
        return HttpResponseRedirect(to.to_url)
    